package com.ml.mall.service.asyn;

import com.ml.mall.bean.page.Page;
import com.ml.mall.bean.req.BaseDateRangeReq;
import com.ml.mall.bean.req.admin.category.AdminCategoryQueryPageReq;
import com.ml.mall.bean.res.admin.category.AdminCategoryQueryReportPageRes;
import com.ml.mall.bean.res.admin.variant.VariantQueryTopRes;
import com.ml.mall.bean.res.admin.variant.vo.VariantQueryTopVO;
import com.ml.mall.bean.res.admin.vo.AdminOverviewSalesByCategoryVO;
import com.ml.mall.bean.res.purchase.PurchaseVariantQueryPageRes;
import com.ml.mall.bean.res.purchase.vo.PurchaseSupplierVO;
import com.ml.mall.bean.res.purchase.vo.PurchaseVariantVO;
import com.ml.mall.bean.res.supplier.SupplierVariantQueryPageRes;
import com.ml.mall.bean.vo.DateValueVO;
import com.ml.mall.mapper.AnalyticsPurchaseMapper;
import com.ml.mall.mapper.AnalyticsSupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.Future;

/**
 * Created by kyyang on 2021/6/8 22:32
 */
@Component
public class AnalyticsPurchaseServiceAsyn {


    @Autowired
    private AnalyticsPurchaseMapper analyticsPurchaseMapper;

    //买家查询消费目录的数量
    @Async
    public Future<Integer> selectPurchaseCategoryPageCount(String timeBegin, String timeEnd, Long companyId,String categoryName) {
        Integer count =  analyticsPurchaseMapper.selectPurcahseCategoryPageCount(timeBegin,timeEnd,companyId,categoryName);
        return new AsyncResult<>(count);

    }
    //买家查询消费目录的的数据
    @Async
    public Future<List<SupplierVariantQueryPageRes>> selectPurchaseCategoryPageList(String timeBegin, String timeEnd, int sortType, Long companyId,String categoryName, int start, int end) {
        List<SupplierVariantQueryPageRes> list =  analyticsPurchaseMapper.selectPurcahseCategoryPageList(timeBegin,timeEnd,sortType,companyId,categoryName,start,end);
        return new AsyncResult<>(list);
    }

    /**
     * @description: 按照卖家 top N
     * @author kyyang
     * @date 2021/7/4 12:46
     * @version 1.0
     */
    @Async
    public Future<List<PurchaseSupplierVO>> selectSalesBySupplierTopN(int topN, String timeBegin, String timeEnd, Long companyId) {
        List<PurchaseSupplierVO> list = analyticsPurchaseMapper.selectSalesBySupplierTopN(topN,timeBegin,timeEnd,companyId);
        return new AsyncResult<>(list);
    }

    /**
     * @description: 按照variant top N
     * @author kyyang
     * @date 2021/7/4 12:46
     * @version 1.0
     */
    @Async
    public Future<List<PurchaseVariantVO>> selectSalesByVariantTopN(int topN, String timeBegin, String timeEnd, Long companyId) {
        List<PurchaseVariantVO> list = analyticsPurchaseMapper.selectSalesByVariantTopN(topN,timeBegin,timeEnd,companyId);
        return new AsyncResult<>(list);
    }

    /**
     * @description: 分类 top N
     * @author kyyang
     * @date 2021/7/4 12:46
     * @version 1.0
     */
    @Async
    public Future<List<DateValueVO>> getPurchaseSpentQueryReportByCategoryTopN(int topN, String timeBegin, String timeEnd, Long companyId) {
        List<DateValueVO> list = analyticsPurchaseMapper.selectPurchaseSpentQueryReportByCategoryTopN(topN,timeBegin,timeEnd,companyId);
        return new AsyncResult<>(list);
    }

    /**
     * @description: 买家中 卖家 top N
     * @author kyyang
     * @date 2021/7/4 14:42
     * @version 1.0
     */
    @Async
    public Future<List<DateValueVO>> getPurchaseSupplierQueryReport(int topN, String timeBegin, String timeEnd, Long companyId) {
        List<DateValueVO> list = analyticsPurchaseMapper.selectPurchaseSupplierQueryReport(topN,timeBegin,timeEnd,companyId);
        return new AsyncResult<>(list);
    }

    /**
     * @description: 消费订单的卖家 分页查询 总记录数
     * @author kyyang
     * @date 2021/7/4 14:53
     * @version 1.0
     */
    @Async
    public Future<Integer> selectPurchaseSupplierQueryPageCount(String timeBegin, String timeEnd, int sortType, String supplierCode, Long companyId) {
        Integer count = analyticsPurchaseMapper.selectPurchaseSupplierQueryPageCount(timeBegin,timeEnd,supplierCode,companyId);
        return new AsyncResult<>(count);
    }

    /**
     * @description: 消费订单的卖家 分页查询 记录明细
     * @author kyyang
     * @date 2021/7/4 14:53
     * @version 1.0
     */
    @Async
    public Future<List<PurchaseSupplierVO>> selectPurchaseSupplierQueryPageList(String timeBegin, String timeEnd, int sortType, String supplierCode, int start, int end, Long companyId) {
        List<PurchaseSupplierVO> list = analyticsPurchaseMapper.selectPurchaseSupplierQueryPageList(timeBegin,timeEnd,sortType,supplierCode,start,end,companyId);
        return new AsyncResult<>(list);
    }



    /**
     * @description: 分页查询买家消费产品 总记录数
     * @author kyyang
     * @date 2021/7/4 15:08
     * @version 1.0
     */
    @Async
    public Future<Integer> selectPurchaseVariantQueryPageCount(String timeBegin, String timeEnd, String supplierCode, Long companyId, String categoryId, String variantName) {
        Integer count = analyticsPurchaseMapper.selectPurchaseVariantQueryPageCount(timeBegin,timeEnd,supplierCode,companyId,categoryId,variantName);
        return new AsyncResult<>(count);
    }

    /**
     * @description: 分页查询买家消费产品 总记录明细
     * @author kyyang
     * @date 2021/7/4 15:08
     * @version 1.0
     */
    @Async
    public Future<List<PurchaseVariantQueryPageRes>> selectPurchaseVariantQueryPageList(String timeBegin, String timeEnd, int sortType, String supplierCode, int start, int end, Long companyId, String categoryId, String variantName) {
        List<PurchaseVariantQueryPageRes> list = analyticsPurchaseMapper.selectPurchaseVariantQueryPageList(timeBegin,timeEnd,sortType,supplierCode,start,end,companyId,categoryId,variantName);
        return new AsyncResult<>(list);
    }

    /**
     * @description: 买家分产品变体查询分析报告：前10名 汇总
     * @author zz
     * @date 2021/10/19 15:08
     * @version 1.0
     */
    @Async
    public Future<List<VariantQueryTopRes>> selectPurchaseVariantQueryTop(BaseDateRangeReq req, int topN, Long companyId) {
        List<VariantQueryTopRes> list=analyticsPurchaseMapper.selectPurchaseVariantQueryTop(req.getTimeBegin(),req.getTimeEnd(),topN,companyId);

        return new AsyncResult<>(list);
    }

    /**
     * @description: 查询买家购买单个商品详情列表
     * @author zz
     * @date 2021/12/01 10:45
     * @version 1.0
     */
    public List<VariantQueryTopVO> selectPurchaseVariantQueryOneByTimeLine(String timeBegin, String timeEnd, String variantId, Long companyId) {
        List<VariantQueryTopVO> list = analyticsPurchaseMapper.selectAdminVariantQueryOneByTimeLine(timeBegin,timeEnd,variantId,companyId);
        return list;
    }

    /**
     * @description: 查询买家购买单个商品详情列表
     * @author zz
     * @date 2021/12/01 10:45
     * @version 1.0
     */
    @Async
    public Future<Integer> selectPurchaseCategoryQueryReportPageCount(String timeBegin, String timeEnd, String categoryName, String industryId, Long supplierId) {
        Integer count = analyticsPurchaseMapper.selectPurchaseCategoryQueryReportPageCount(timeBegin,timeEnd,categoryName,industryId,supplierId);
        return new AsyncResult<>(count);
    }

    /**
     * @description: 查询买家购买单个商品详情列表
     * @author zz
     * @date 2021/12/01 10:45
     * @version 1.0
     */
    @Async
    public Future<List<AdminCategoryQueryReportPageRes>> selectPurchaseCategoryQueryReportPageList(String timeBegin, String timeEnd, int sortType, String categoryName, String industryId, int start, int end,Long supplierId) {
        List<AdminCategoryQueryReportPageRes> list = analyticsPurchaseMapper.selectPurchaseCategoryQueryReportPageList(timeBegin, timeEnd, sortType, categoryName,industryId ,start, end ,supplierId);
        return new AsyncResult<>(list);
    }
}
